/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aiaudio.database.tables;

import aiaudio.database.Family;
import aiaudio.database.qualifiers.LongQualifier;
import aiaudio.database.qualifiers.StringQualifier;
import java.io.IOException;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;

/**
 *
 * @author nastya
 */
public class StatisticsTable extends TableStructure{

    private static final Family VALUES = new Family("t");
    
    private static final LongQualifier ARTIST = new LongQualifier("artists");
    private static final LongQualifier USERS = new LongQualifier("users");
    private static final LongQualifier RATINGS = new LongQualifier("ratings");
    private static final LongQualifier RATINGS_TO_FIND = new LongQualifier("ratings_to_find");
    private static final LongQualifier RATINGS_KNOWN = new LongQualifier("ratings_known");
    private static final LongQualifier GROUP_COUNT = new LongQualifier("ratings_known");
    private static final LongQualifier DICTIONARY_COUNT = new LongQualifier("ratings_known");
    private static final LongQualifier DICTIONARY_LENGTH = new LongQualifier("ratings_known");
    
    private static final StringQualifier ROW_COUNT = new StringQualifier("count");
    private static final StringQualifier ROW_TIME = new StringQualifier("time");
    private static final StringQualifier ROW_SPLITTED = new StringQualifier("splitted");
    private static final StringQualifier ROW_TEST_SET = new StringQualifier("testset");
    private static final StringQualifier ROW_NETWORK = new StringQualifier("network");
    private static final StringQualifier ROW_REDUCED = new StringQualifier("reduced");
    private static final StringQualifier ROW_PARAMETERS = new StringQualifier("parameters");
    
    
    @Override
    public Family[] getAllFamilies() {
        return new Family[]{VALUES};
    }
    
    public static void addCounts(HTable tableInstance, long artistCount, 
            long usersCount, long ratingsCount) throws IOException{
        Put put = new Put(ROW_COUNT.getNameAsBytes());
        addDataSavePreviousRow(put, VALUES, ARTIST, artistCount);
        addDataSavePreviousRow(put, VALUES, USERS, artistCount);
        addDataSavePreviousRow(put, VALUES, RATINGS, artistCount);
        tableInstance.put(put);
    }
    
    public static void addTime(HTable tableInstance, String algorithmName, long time) throws IOException{
        Put put = new Put(ROW_TIME.getNameAsBytes());
        addDataSavePreviousRow(put, VALUES, new LongQualifier(algorithmName), time);
        tableInstance.put(put);
    }
    
    public static void addSplit(HTable tableInstance, long ratingsCount) throws IOException{
        Put put = new Put(ROW_SPLITTED.getNameAsBytes());
        addDataSavePreviousRow(put, VALUES, RATINGS, ratingsCount);
        tableInstance.put(put);
    }
    
    public static void addTestSet(HTable tableInstance, long ratingsCount, long ratingsKnown) throws IOException{
        Put put = new Put(ROW_TEST_SET.getNameAsBytes());
        addDataSavePreviousRow(put, VALUES, RATINGS_TO_FIND, ratingsCount);
        addDataSavePreviousRow(put, VALUES, RATINGS_KNOWN, ratingsKnown);
        tableInstance.put(put);
    }
    
    public static void addNetwork(HTable tableInstance, long groupsCount) throws IOException{
        Put put = new Put(ROW_NETWORK.getNameAsBytes());
        addDataSavePreviousRow(put, VALUES, GROUP_COUNT, groupsCount);
        tableInstance.put(put);
    }

    public static void addReduce(HTable tableInstance, long dictionaryCount, long dictionaryLength) throws IOException{
        Put put = new Put(ROW_REDUCED.getNameAsBytes());
        addDataSavePreviousRow(put, VALUES, DICTIONARY_COUNT, dictionaryCount);
        addDataSavePreviousRow(put, VALUES, DICTIONARY_LENGTH, dictionaryLength);
        tableInstance.put(put);
    }
    
}
